// Object.keys(obj)：获取传入对象的属性名数组
// Object.values(obj)：获取传入对象的属性值数组
// Object.entries(obj)：获取传入对象的属性名和属性值的键值对数组

let obj = {
    name: "Hydra",
    age: 35,
    sex: "男",
    friend: {
        name: "刘煜鑫",
        age: 20
    }
}

let keys = Object.keys(obj);
let values = Object.values(obj);
let entries = Object.entries(obj);

console.log("keys = ",keys);
console.log("values = ",values);
console.log("entries = ",entries);

// 通过keys遍历
console.log("----------keys------------")
for (let v of keys) {
    console.log(v," = ",obj[v]);
}

console.log("----------values------------")
for (let v of values) {
    console.log(v);
}

console.log("----------entries------------")
for (let v of entries) {
    console.log(v[0]," = ",v[1]);
}

// 额外旧知识：对象可以直接使用for...in循环遍历
console.log("----------for...in------------")
for (let key in obj) {
    console.log(key," = ",obj[key])
}